package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.*;

/**
 * @author Jason Whiting
 */
public class PartsAtServiceFacility extends BusinessObject
{

    private int quantityOnHand = 2;
    private int reorderLevel = 1;
    private int repurchaseQuantity = 1;
    private int quantityOnOrder = 0;
    private String serviceFacilityId;
    private ServiceFacility serviceFacility;
    private String partId;
    private Part part;

    /**
     * Creates a new instance of BusinessObject
     * @param id
     */
    public PartsAtServiceFacility(String id)
    {
        super(id);
    }//constructor

    //Quick Access Method
    public void save() throws DataException
    {
        try
        {
            PartsAtServiceFacilityDAO.getInstance().save(this);
        } catch (DataException e)
        {
            e.printStackTrace();
        }
    }

    /** @return the quantityOnHand     */
    public int getQuantity()
    {
        return quantityOnHand;
    }

    /** @param actualPrice the actualPrice to set     */
    public void setQuantity(int quantityOnHand)
    {
        this.quantityOnHand = quantityOnHand;
        setDirty(true);
    }

    /** @return the serviceFacilityId     */
    public String getServiceFacilityId()
    {
        return serviceFacilityId;
    }

    /** @param serviceFacilityId the serviceFacilityId to set     */
    public void setServiceFacilityId(String serviceFacilityId)
    {
        this.serviceFacilityId = serviceFacilityId;
        setDirty(true);
    }

    /** @return the serviceFacility     */
    public ServiceFacility getServiceFacility() throws Exception
    {
        if (serviceFacility == null)
        {
            serviceFacility = ServiceFacilityDAO.getInstance().read(serviceFacilityId);
        }
        return serviceFacility;
    }

    /** @param serviceFacility the serviceFacility to set     */
    public void setServiceFacility(ServiceFacility serviceFacility)
    {
        this.serviceFacility = serviceFacility;
        setServiceFacilityId(serviceFacility.getId());
        setDirty(true);
    }

    /** @return the partId     */
    public String getPartId()
    {
        if (partId == null)
        {
            partId = part.getId();
        }
        return partId;
    }

    /** @param partId the partId to set     */
    public void setPartId(String partId)
    {
        this.partId = partId;
        setDirty(true);
    }

    /** @return the part     */
    public Part getPart() throws Exception
    {
        if (part == null)
        {
            part = PartDAO.getInstance().read(partId);
        }
        return part;
    }

    /** @param part the part to set     */
    public void setPart(Part part)
    {
        this.part = part;
        setPartId(part.getId());
        setDirty(true);
    }

    /**
     * @return the reorderLevel
     */
    public int getReorderLevel()
    {
        return reorderLevel;
    }

    /**
     * @param reorderLevel the reorderLevel to set
     */
    public void setReorderLevel(int reorderLevel)
    {
        this.reorderLevel = reorderLevel;
        setDirty(true);
    }

    /**
     * @return the repurchaseQuantity
     */
    public int getRepurchaseQuantity()
    {
        return repurchaseQuantity;
    }

    /**
     * @param repurchaseQuantity the repurchaseQuantity to set
     */
    public void setRepurchaseQuantity(int repurchaseQuantity)
    {
        this.repurchaseQuantity = repurchaseQuantity;
        setDirty(true);
    }

    /**
     * @return the quantityOnOrder
     */
    public int getQuantityOnOrder()
    {
        return quantityOnOrder;
    }

    /**
     * @param quantityOnOrder the quantityOnOrder to set
     */
    public void setQuantityOnOrder(int quantityOnOrder)
    {
        this.quantityOnOrder = quantityOnOrder;
        setDirty(true);
    }
}
